//
//  VisitorTableViewController.swift
//  Practice
//
//  Created by miaozhihui on 2016/12/2.
//  Copyright © 2016年 DeKuTree. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    /// 用户登录标记
    fileprivate var userLogon = false // UserAccountViewModel.sharedUserAccount.userLogin
    
    /// 访客视图
    var visitorView:VisitorView?
    
    override func loadView() {
        userLogon ? super.loadView() : setupVisitorView()
    }
    
    /// 设置访客视图
    fileprivate func setupVisitorView() {
        // 替换根视图
        visitorView = VisitorView()
        view = visitorView
        
        // 添加监听方法
        visitorView?.registerButton.addTarget(self, action: #selector(visitorViewDidRegister), for: .touchUpInside)
        visitorView?.loginButton.addTarget(self, action: #selector(visitorViewDidLogin), for: .touchUpInside)
        
        // 设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(visitorViewDidRegister))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(visitorViewDidLogin))
        
    }
}

extension VisitorTableViewController {
    func visitorViewDidRegister() {
        print("注册")
    }
    func visitorViewDidLogin() {
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        present(nav, animated: true, completion: nil)
        
    }
}
